$(function () {
  // 输入框
  $(".input-one input").on({
    focus: function () {
      $(this).css("color", "#000");
      if ($(this).val() == "输入关键字搜索商品/店铺/品牌") {
        $(this).val("");
      }
    },
    blur: function () {
      if ($(this).val() != "") {
        $(this).val() = $(this).innerHTML();
      }
      $(this).css("color", "rgb(204, 204, 204)");
      $(this).val("输入关键字搜索商品/店铺/品牌");
    },
  });
  $(".search-nav span").on("mouseover", function () {
    $(this).css("color", "#FF6600").siblings().css("color", "");
  });

  // 倒计时
  var fen = document.querySelector(".djs");
  var m = 59;
  var ss = 59;
  countDown();
  setInterval(function () {
    countDown();
  }, 1000);
  function countDown() {
    if (m < 10 && ss < 10) {
      fen.innerHTML =
        "<span>" +
        "00" +
        "</span>" +
        "<span>" +
        "0" +
        m +
        "</span>" +
        ":" +
        "<span>" +
        0 +
        ss +
        "</span>";
    } else if (m < 10 && ss > 10) {
      fen.innerHTML =
        "<span>" +
        "00" +
        "</span>" +
        ":" +
        "<span>" +
        "<span>" +
        "0" +
        m +
        "</span>" +
        ":" +
        "<span>" +
        ss +
        "</span>";
    } else if (m > 10 && ss > 10) {
      fen.innerHTML =
        "<span>" +
        "00" +
        "</span>" +
        ":" +
        "<span>" +
        m +
        "</span>" +
        ":" +
        "<span>" +
        ss +
        "</span>";
    } else if (m > 10 && ss < 10) {
      fen.innerHTML =
        "<span>" +
        "00" +
        "</span>" +
        ":" +
        "<span>" +
        m +
        "</span>" +
        ":" +
        "<span>" +
        "0" +
        ss +
        "</span>";
    }
    if (m == 0 && ss == 0) {
      m = 00;
      ss = 00;
    } else if (m >= 0) {
      if (ss > 0) {
        ss--;
      } else if (ss == 0) {
        m--;
        ss = 59;
      }
    }
  }

  // 切换cur
  $(".fc span").on("mouseover", function () {
    $(this).addClass("cur").siblings().removeClass("cur");
  });

  // 右边固定栏
  $(".ybgdl ul li").on("mouseover", function () {
    $(this)
      .css({
        backgroundColor: "#f20",
      })
      .siblings()
      .css({
        backgroundColor: "#333",
      });
    $(this).css("transition", ".5s");
  });
  $(".ybgdl ul li").on("mouseout", function () {
    $(this).css("backgroundColor", "#333");
    $(this).css("transition", ".5s");
  });

  $(".ybgdl ul li").on("mouseover", function () {
    $(this).children("p").css("left", "-50px");
    $(this).children("p").css("transition", ".5s");
  });
  $(".ybgdl ul li").on("mouseout", function () {
    $(this).children("p").css("left", "50px");
    $(this).children("p").css("transition", ".5s");
  });
  $(".ybgdl ul li").on("mouseover", function () {
    $(this).children(".ybdhl-da").css("left", "-70px");
    $(this).children(".ybdhl-da").css("transition", ".5s");
  });
  $(".ybgdl ul li").on("mouseout", function () {
    $(this).children(".ybdhl-da").css("left", "70px");
    $(this).children(".ybdhl-da").css("transition", ".5s");
  });

  // 搜索框随页面滚动到一定距离显示
  var search = $(".lqzx").offset().top;
  $(window).scroll(function () {
    if ($(document).scrollTop() >= search - 130) {
      $(".nav-hiden").fadeIn(".3s");
    } else {
      $(".nav-hiden").fadeOut();
    }
  });
  // 左边固定栏

  $(window).scroll(function () {
    if ($(document).scrollTop() >= search - 120) {
      $(".zbgdl").fadeIn("0s");
    } else {
      $(".zbgdl").fadeOut();
    }
  });

  $(".zbgdl li").on({
    click: function () {
      // console.log($(this).index());
      var peidui = $(".bk .daohan").eq($(this).index()).offset().top;
      $("body, html")
        .stop()
        .animate({
          scrollTop: peidui - 50,
        });
      $(this).addClass("zbgdl-cur").siblings("li").removeClass("zbgdl-cur");
    },
    mouseover: function () {
      $(this).addClass("zbgdl-curs").siblings("li").removeClass("zbgdl-curs");
    },
  });
  $(".zbgdl ul li").on("mouseout", function () {
    $(this).removeClass("zbgdl-curs");
  });
  // 返回顶部
  $(".fhdbtop, .hui, .ding").on({
    click: function () {
      $("body, html").stop().animate({
        scrollTop: 0,
      });
      // $(this).addClass("zbgdl-cur").siblings("li").removeClass("zbgdl-cur");
    },
    mouseover: function () {
      $(this).addClass("zbgdl-curs");
    },
    mouseout: function () {
      $(this).removeClass("zbgdl-curs");
    },
  });

  // 左边固定栏随页面滚动而滚动
  $(window).scroll(function () {
    $(".bk .yem").each(function (i, ele) {
      if ($(document).scrollTop() >= $(ele).offset().top - 150) {
        $(".zbgdl li")
          .eq(i)
          .addClass("zbgdl-cur")
          .siblings()
          .removeClass("zbgdl-cur");
      }
    });
  });

  // 苏宁直播鼠标经过显示二维码
  $(".snzb-zbtu li").on({
    mouseover: function () {
      $(this).children(".snzb-erweimas-main").show();
    },
    mouseout: function () {
      $(this).children(".snzb-erweimas-main").hide();
    },
  });

  // 商品滚动
  //0.定义变量保存偏移位
  var offsetTops = 0;
  //1.让图片滚动起来
  var timers;
  function autoPlays() {
    timers = setInterval(function () {
      // offset += 1;//反方向
      offsetTops += -238;
      //表示超过两张图片的显示范围
      if (offsetTops <= -952) {
        //因为改成了六张图片所以要从-600变为-1200
        offsetTops = 0;
      }
      $(".smks ul").css("marginTop", offsetTops);
      $(".smks ul").css("transition", "2s");
    }, 4000);
  }

  autoPlays();

  $(".smks ul li").hover(
    function () {
      //停止滚动
      clearInterval(timers);
    },
    function () {
      //继续滚动
      autoPlays();
    }
  );
  //0.定义变量保存偏移位
  var offsetTop = 0;
  //1.让图片滚动起来
  var timer;
  function autoPlay() {
    timer = setInterval(function () {
      // offset += 1;//反方向
      offsetTop += -198;
      //表示超过两张图片的显示范围
      if (offsetTop <= -792) {
        //因为改成了六张图片所以要从-600变为-1200
        offsetTop = 0;
      }
      $(".smk ul").css("marginTop", offsetTop);
      $(".smk ul").css("transition", "2s");
    }, 6330);
  }

  autoPlay();

  $(".smk ul li").hover(
    function () {
      //停止滚动
      clearInterval(timer);
    },
    function () {
      //继续滚动
      autoPlay();
    }
  );
  // 购物车
  // $(".gwuche").on("mouseover", function () {
  //   $(".ybgdl").stop().show();
  // });
  // $(".gwuche").on("mouseout", function () {
  //   $(".ybgdl").stop().hide();
  // });
});
